<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

class ImRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(Request $request)
    {
        switch ($this->method()) {
            case 'POST':
                $rules =  [
                    'id' => [
                        'nullable',
                        Rule::exists('users')->where(function ($query) {
                            $query->whereNull('deleted_at');
                        }),
                    ],
                    'alias'=>'required|max:20',
                    'im' => [
                        'required',
                        Rule::in(['qq', 'wx']),
                    ],
                    'value'=>'required'
                ];
                break;
            case 'PATCH':
                $selfId = $request->route('im')->id;
                $rules =  [
                    'im' => [
                        'required',
                        Rule::in(['qq', 'wx']),
                    ],
                    'alias' =>"required|max:20",
                    'value'=>'required',
                ];
                break;

        }
        return $rules;
    }
}
